package com.atguigu.yygh.order.controller;


import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.common.utils.JwtHelper;
import com.atguigu.yygh.enums.OrderStatusEnum;
import com.atguigu.yygh.model.order.OrderInfo;
import com.atguigu.yygh.order.service.OrderInfoService;
import com.atguigu.yygh.vo.order.OrderQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2023-03-30
 */
@RestController
@RequestMapping("/user/order")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    @PostMapping("/{patientId}/{scheduleId}")
    public R submit(@PathVariable Long patientId,@PathVariable String scheduleId){
        Long orderId = orderInfoService.submitOrdder(patientId,scheduleId);
        return R.ok().data("orderId", orderId);
    }

    @PostMapping("/page/{pageNum}/{pageSize}")
    public R getOrderPage(@PathVariable Integer pageNum,
                          @PathVariable Integer pageSize,
                          @RequestBody OrderQueryVo orderQueryVo,
                          @RequestHeader String token){
        orderQueryVo.setUserId(JwtHelper.getUserId(token));
        Page<OrderInfo> page = orderInfoService.getOrderPage(pageNum,pageSize,orderQueryVo);
        return R.ok().data("total",page.getTotal()).data("items",page.getRecords());
    }

    @GetMapping("/status/list")
    public R getStatusList(){
        List<Map<String, Object>> statusList = OrderStatusEnum.getStatusList();
        return R.ok().data("items",statusList);
    }

    //根据订单id查询订单信息
    //根据订单id查询订单详情
    @GetMapping("/detail/{orderId}")
    public R getOrders(@PathVariable Long orderId) {
        OrderInfo orderInfo = orderInfoService.getOrderInfo(orderId);
        return R.ok().data("orderInfo",orderInfo);
    }
}